import 'package:aweb5/generated/json/material_list_entity_helper.dart';
import 'package:aweb5/generated/json/material_type_entity_helper.dart';
import 'package:aweb5/util/DialogUtil.dart';
import 'package:aweb5/util/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:aweb5/util/NaviUtil.dart';
//import 'package:fluttertoast/fluttertoast.dart';
import 'package:aweb5/util/toast_util.dart';
import 'package:aweb5/util/HttpClient.dart';
import 'package:aweb5/config/Config.dart';
import 'package:aweb5/Constants.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:aweb5/custom/pull_torefresh.dart';
import 'package:aweb5/style.dart';
import 'package:aweb5/util/toast_util.dart' as P;
import 'package:load/load.dart';
import 'package:aweb5/bean/aplus/material_list_entity.dart';
import 'package:aweb5/bean/aplus/material_type_entity.dart';
import 'package:aweb5/bean/aplus/common_result_entity.dart';
import 'package:aweb5/generated/json/common_result_entity_helper.dart';
import 'package:aweb5/widgetlib/menu_widget.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:aweb5/util/NaviUtil.dart';
import 'package:aweb5/util/DateUtil.dart';
import 'package:aweb5/bean/aplus/group_list_entity.dart';
import 'package:aweb5/bean/aplus/group_plan_list_entity.dart';
import 'package:aweb5/businuss/sucai_pub_widget.dart';

class ChooseMission extends StatefulWidget {
  List<DropdownMenuItem<String>> sortItems;
  String _selectedSort = "";
  List<GroupPlanListDataGroup> groupList;
  String groupId;
  ChooseMission(this.sortItems, this._selectedSort, this.groupList);

  @override
  _ChooseMissionState createState() => _ChooseMissionState();
}

class _ChooseMissionState extends State<ChooseMission> {
  RefreshController refreshController =
      RefreshController(initialRefresh: false);
  int itemCount = 10;
  BuildContext context;
  String chip = "test";

  //搜索名
  String search = "";
  int currentPage = 1;
  String type = "";
  TextEditingController textEditingController = TextEditingController();

  //任务名
  TextEditingController missionController = TextEditingController();
  String date = "";
//  String groupId = "";
  String time = "";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
//    Future.delayed(Duration(seconds: 5),(){
//    requestMaterial();

//    });
//    groupId = widget.groupList[0].id.toString();
  }

  @override
  Widget build(BuildContext context) {
    this.context = context;
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        leading: SucaiPubWidget.appBarBack(
            context, EdgeInsets.only(left: ScreenUtil().setWidth(20))),
        elevation: 0,
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          SizedBox(
            height: ScreenUtil().setHeight(23),
          ),
          Row(
            children: <Widget>[
              SizedBox(
                width: ScreenUtil().setWidth(26),
              ),
              Text(
                "任务名",
                style: TextStyle(
                    color: Color(0xff101010),
                    fontSize: ScreenUtil().setSp(16),
                    fontWeight: FontWeight.bold),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setHeight(12),
          ),
          Container(
            alignment: Alignment.centerLeft,
            width: ScreenUtil().setWidth(361),
            height: ScreenUtil().setHeight(44),
            child: TextField(
              decoration: InputDecoration(border: InputBorder.none),
              controller: missionController,
            ),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(ScreenUtil().setWidth(4)),
                border: Border.all(color: Color(0xffDCDFE6))),
          ),
          SizedBox(
            height: ScreenUtil().setHeight(23),
          ),
          Row(
            children: <Widget>[
              SizedBox(
                width: ScreenUtil().setWidth(26),
              ),
              Text(
                "选择任务包",
                style: TextStyle(
                    color: Color(0xff101010),
                    fontSize: ScreenUtil().setSp(16),
                    fontWeight: FontWeight.bold),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setHeight(12),
          ),
          GestureDetector(
            child: Container(
              alignment: Alignment.centerLeft,
              width: ScreenUtil().setWidth(361),
              height: ScreenUtil().setHeight(44),
              child: Container(
                child: Row(
                  children: <Widget>[
                    SizedBox(
                      width: ScreenUtil().setWidth(10),
                    ),
                    Container(
                        padding: EdgeInsets.symmetric(
                            horizontal: ScreenUtil().setWidth(3)),
                        alignment: Alignment.centerLeft,
                        height: ScreenUtil().setHeight(name.isEmpty ? 0 : 24),
                        child: Text(
                          "${name}",
                          style: TextStyle(
                              color: Color(0xff5A5E66),
                              fontSize: ScreenUtil().setSp(12)),
                        ),
                        decoration: BoxDecoration(
                          color: Color(0xffF0F2F5),
//                          borderRadius: BorderRadius.circular(ScreenUtil().setHeight(3)),
                          borderRadius: BorderRadius.only(
                              bottomLeft:
                                  Radius.circular(ScreenUtil().setWidth(3)),
                              topLeft:
                                  Radius.circular(ScreenUtil().setWidth(3))),
                        )),
                    GestureDetector(
                      child: Container(
                        width: ScreenUtil().setWidth(name.isEmpty ? 0 : 24),
                        height: ScreenUtil().setHeight(24),
                        decoration: BoxDecoration(
                          color: Color(0xffF0F2F5),
//                          borderRadius: BorderRadius.circular(ScreenUtil().setHeight(3)),
                          borderRadius: BorderRadius.only(
                              topRight:
                                  Radius.circular(ScreenUtil().setWidth(3)),
                              bottomRight:
                                  Radius.circular(ScreenUtil().setWidth(3))),
                        ),
                        padding: EdgeInsets.all(ScreenUtil().setWidth(2)),
                        child: Image.asset(
                          "assets/assist/guanbi.png",
                          width: ScreenUtil().setWidth(name.isEmpty ? 0 : 18),
                          height: ScreenUtil().setHeight(name.isEmpty ? 0 : 18),
                        ),
                      ),
                      onTap: () {
                        this.name = "";
                        this.taskid = "";
                        setState(() {});
                      },
                    )
                  ],
                ),
              ),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(ScreenUtil().setWidth(4)),
                  border: Border.all(color: Color(0xffDCDFE6))),
            ),
            onTap: () {
              _showDialog();
            },
          ),
//          SizedBox(
//            height: ScreenUtil().setHeight(21),
//          ),
//          Row(
//            children: <Widget>[
//              SizedBox(
//                width: ScreenUtil().setWidth(26),
//              ),
//              Text(
//                "选择群",
//                style: TextStyle(
//                    color: Color(0xff101010),
//                    fontSize: ScreenUtil().setSp(16),
//                    fontWeight: FontWeight.bold),
//              )
//            ],
//          ),
//          SizedBox(
//            height: ScreenUtil().setHeight(12),
//          ),
//          Container(
//            padding: EdgeInsets.only(left: ScreenUtil().setWidth(5)),
//            alignment: Alignment.centerLeft,
//            width: ScreenUtil().setWidth(361),
//            height: ScreenUtil().setHeight(44),
//            decoration: BoxDecoration(
//                borderRadius: BorderRadius.circular(ScreenUtil().setWidth(4)),
//                border: Border.all(color: Color(0xffDCDFE6))),
//            child: MenuWidget(
//              widget.sortItems,
//              widget.sortItems[0].value,
//              call: setGroup,
//              width: ScreenUtil().setWidth(361),
//            ),
//          ),
          SizedBox(
            height: ScreenUtil().setHeight(21),
          ),
          GestureDetector(
            child: Row(
              children: <Widget>[
                SizedBox(
                  width: ScreenUtil().setWidth(26),
                ),
                Text(
                  "设置发布时间",
                  style: TextStyle(
                      color: Color(0xff101010),
                      fontSize: ScreenUtil().setSp(16),
                      fontWeight: FontWeight.bold),
                )
              ],
            ),
            onTap: () {},
          ),

          SizedBox(
            height: ScreenUtil().setHeight(21),
          ),
          GestureDetector(
            child: Container(
              width: ScreenUtil().setWidth(361),
              height: ScreenUtil().setHeight(44),
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(10),
                  right: ScreenUtil().setWidth(10),
                  top: ScreenUtil().setHeight(12)),
              child: Text(time,
                  style: TextStyle(
                      color: Color(0xff101010),
                      fontSize: ScreenUtil().setSp(14))),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(ScreenUtil().setWidth(4)),
                  border: Border.all(color: Color(0xffDCDFE6))),
            ),
            onTap: () {
              DatePicker.showDateTimePicker(context,
                  showTitleActions: true,
                  minTime: DateTime.now(),
                  maxTime: DateTime.now().add(Duration(days: 20)),
                  onChanged: (date) {
                print('change $date in time zone ' +
                    date.timeZoneOffset.inHours.toString());
              }, onConfirm: (date) {
                print('confirm $date');
//                    string = date.day.toString();
                int now = DateTime.now().millisecondsSinceEpoch;
                int select = date.millisecondsSinceEpoch;
                if (select - now < 1000 * 60 * 10) {
                  Toast.show(msg: "请选择10分钟之后");
                } else {
//                  time = DateUtil.formatDateTimeToString(date);
                  time = date.toString().split(".")[0];
                }
//                        _overlayEntry.remove();
                setState(() {});
              }, onCancel: () {
//                        _overlayEntry.remove();
              }, locale: LocaleType.zh);
            },
          ),
          SizedBox(height: ScreenUtil().setHeight(10),),
          Row(
            children: <Widget>[
              SizedBox(width: ScreenUtil().setWidth(25),),
              Text("目前不支持10分钟之内的时间设置",style: TextStyle(color: Colors.grey),),
              Expanded(child: Text(""))
              
            ],
            
          )
          ,
          SizedBox(
            height: ScreenUtil().setHeight(23),
          ),
          GestureDetector(
            child: Container(
              width: ScreenUtil().setWidth(361),
              height: ScreenUtil().setHeight(40),
              alignment: Alignment.center,
              decoration: redButtonStyle,
              child: Text(
                "确认添加",
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(18)),
              ),
            ),
            onTap: () {
//              showModalBottomSheet(
//                  context: this.context,
//                  builder: (bui) {
//                    return b12();
//                  });
              if (missionController.text.isEmpty) {
                Toast.show(msg: "请填写任务名");
                return;
              }
              if (taskid == "") {
                Toast.show(msg: "请选择任务包");
                return;
              }

              if (time == "") {
                Toast.show(msg: "请选择时间");
                return;
              }
              requetSend();
            },
          ),
          SizedBox(
            height: ScreenUtil().setHeight(26),
          ),
          Container(
            padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(26),
                right: ScreenUtil().setWidth(26)),
            child: Text(
              "*我们会跟据智能助理的排期时间按顺序发出，并不是实时的，请耐心等待。",
              maxLines: 2,
              style: TextStyle(
                  color: Color(0xff101010), fontSize: ScreenUtil().setSp(14)),
            ),
          )
        ],
      ),
    );
  }

//  void setGroup(String group) {
//    this.groupId = group;
//  }

  _showDialog() {
    search = "";
    showModalBottomSheet(
        isScrollControlled: true,
        context: this.context,
        builder: (c) {
//          requestMaterial();
          return SizedBox(
            height: ScreenUtil().setHeight(607),
            child: b12(),
          );
        });
  }

  Widget b12() {
    return DialogStateFul(sucaibaoCall);
  }


  String name = "";
  void sucaibaoCall(String taskid, String name) {
    this.taskid = taskid;
    this.name = name;
    setState(() {});
  }

  TextStyle b() {
    return TextStyle(
        color: Color(0xff101010),
        fontSize: ScreenUtil().setSp(16),
        fontWeight: FontWeight.bold);
  }

  TextStyle b1() {
    return TextStyle(
        color: Color(0xff101010), fontSize: ScreenUtil().setSp(14));
  }

  TextStyle grey() {
    return TextStyle(
        color: Color(0xffa7a7a7), fontSize: ScreenUtil().setSp(14));
  }

  String taskid = "";

  // 添加
  void requetSend() async {
     DialogUtil.showloadingdialog(context);
    try {
      Map<String, dynamic> map = Map<String, dynamic>();

      map["member_id"] = Constants.memberInfoEntity.data.memberId;
      map["task_id"] = taskid;
      map["send_time"] = time;
      map["group_id"] = Constants.currentGroupId;
      map["name"] = missionController.text;

      Map<String, dynamic> map1 = await HttpClient.requestLogin(
          Config.requestApi + 'light/send/add',
          data: map);

      CommonResultEntity loginEntity = new CommonResultEntity();

      loginEntity = commonResultEntityFromJson(loginEntity, map1);

      DialogUtil.pop(context);
      if (loginEntity.code == null || loginEntity.code != 200) {
//        Fluttertoast.showToast(msg: "null");
        Toast.show(msg: loginEntity.msg);

        return;
      }
      if (loginEntity.code == 200) {
        Toast.show(msg: "添加成功");
        NaviUtil.pop(this.context);



      }
    } catch (e) {
      print(e.toString());
       DialogUtil.pop(context);
    }
  }
}

class DialogStateFul extends StatefulWidget {
//  List<MaterialListDataData> list;
//  Function refresh;
//  Function load;
//  RefreshController refreshController;
//  MaterialListEntity materialListEntity;
  Function call;
  DialogStateFul(this.call);

  @override
  _DialogStateFulState createState() => _DialogStateFulState();
}

class _DialogStateFulState extends State<DialogStateFul> {
  bool check = false;

  BuildContext context;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {

      requestMaterialType();
      requestMaterial(false);

    });

  }

  @override
  Widget build(BuildContext context) {
    this.context = context;
    return buildBody();
  }

//  materialTypeUrl.isEmpty?
//  Image.asset(
//  "assets/assist/wenjian1.png",
//  width: ScreenUtil().setWidth(48),
//  height: ScreenUtil().setHeight(48),
//  ):NetworkImage(materialTypeUrl)

  MaterialTypeEntity materialTypeEntity;
  Widget cate() {
    return Container(
      height: ScreenUtil().setHeight(80),
      width: ScreenUtil().setWidth(414),
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemBuilder: (con, index) {
          return GestureDetector(
            child: Container(
              margin: EdgeInsets.only(right: ScreenUtil().setWidth(27)),
              child: Column(
                children: <Widget>[
                  Image.network(
                    "${materialTypeEntity.data[index].imgUrl}",
                    width: ScreenUtil().setWidth(48),
                    height: ScreenUtil().setHeight(48),
                  ),
                  SizedBox(
                    height: ScreenUtil().setHeight(10),
                  ),
                  Text(
                    "${materialTypeEntity.data[index].name}",
                    style: b1(),
                  )
                ],
              ),
            ),
            onTap: () {
              materialTypeUrl = materialTypeEntity.data[index].imgUrl;
              typeid = materialTypeEntity.data[index].id.toString();
              requestMaterial(false);
            },
          );
        },
        itemCount:
            materialTypeEntity == null ? 0 : materialTypeEntity.data.length,
      ),
    );
  }

  TextEditingController textEditingController = TextEditingController();
  RefreshController refreshController = RefreshController(initialRefresh: false);
//  MaterialListEntity materialListEntity = null;
  List<MaterialListDataData> list = List();
  Widget buildRefresh() {
    return PullToRefresh().buildRefresh(
        refresh: refresh,
        load: load,
        child: CustomScrollView(
          slivers: <Widget>[
//                      SliverToBoxAdapter(
//                        child: Container(
//                          child: Text(
//                            "素材库",
//                            style: b(),
//                          ),
//                          margin: EdgeInsets.only(
//                              bottom: ScreenUtil().setHeight(20)),
//                        ),
//                      ),
//                      SliverGrid(
//                        delegate: SliverChildBuilderDelegate(
//                          (BuildContext context, int index) {
//                            return sheetDialogItem();
//                          },
//                          childCount: 10,
//                        ),
//                        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//                          mainAxisSpacing: 10, // 主轴间距
//                          crossAxisSpacing: 10, // 纵轴间距
//                          crossAxisCount: 3, // 纵轴子元素个数
//                          childAspectRatio: 0.7,
//                        ),
//                      ),

            SliverToBoxAdapter(
              child: Container(
                child: Text(
                  "任务包",
                  style: b(),
                ),
                margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(20)),
              ),
            ),
            SliverGrid(
              delegate: SliverChildBuilderDelegate(
                (BuildContext context, int index) {
                  return sheetDialogItem(index);
                },
                childCount: list.length,
              ),
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                mainAxisSpacing: 10, // 主轴间距
                crossAxisSpacing: 10, // 纵轴间距
                crossAxisCount: 3, // 纵轴子元素个数
                childAspectRatio: 1,
              ),
            ),
          ],
        ),
        pulldown: false,
        pullup: true,
        refreshController: refreshController);
  }

  Widget buildBody() {
    return Container(
      padding: EdgeInsets.only(
          left: ScreenUtil().setWidth(16),
          right: ScreenUtil().setWidth(11),
          top: ScreenUtil().setHeight(20)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              GestureDetector(
                child: Container(
                  width: ScreenUtil().setWidth(55),
                  height: ScreenUtil().setHeight(55),
                  padding: EdgeInsets.only(
                    right: ScreenUtil().setWidth(30),
                      bottom: ScreenUtil().setHeight(15),
                      top: ScreenUtil().setHeight(15)
                  ),
                  child: Image.asset(
                    "assets/assist/guanbib.png",
                    width: ScreenUtil().setWidth(24),
                    height: ScreenUtil().setHeight(24),
                  ),
                ),
                onTap: () {
                  NaviUtil.pop(this.context);
                },
              ),
              GestureDetector(
                child: Container(
                  alignment: Alignment.center,
                  width: ScreenUtil().setWidth(94),
                  height: ScreenUtil().setHeight(40),
                  decoration: redButtonStyleWithBorder,
                  child: Text(
                    "确认选择",
                    style: TextStyle(
                        color: Color(0xffF94F68),
                        fontSize: ScreenUtil().setSp(14)),
                  ),
                ),
                onTap: () {
                  if (taskid.isEmpty) {
                    Toast.show(msg: "请选择任务包");
                    return;
                  }
                  widget.call(taskid, name);
                  NaviUtil.pop(context);
                },
              )
            ],
          ),
          Container(
            alignment: Alignment.center,
            width: ScreenUtil().setWidth(381),
            height: ScreenUtil().setHeight(39),
            decoration: BoxDecoration(
                color: Color(0xfff1f1f1),
                borderRadius: BorderRadius.circular(5)),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                SizedBox(
                  width: ScreenUtil().setWidth(20),
                ),
                Expanded(
                    child: TextField(
                  controller: textEditingController,
                  decoration: InputDecoration(
                      hintText: "输入团品或关键字搜索",
                      hintStyle: TextStyle(color: Color(0xffa3a3a3)),
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.only(bottom: 12)),
                )),
                GestureDetector(
                  child: Image.asset(
                    "assets/search1.png",
                    width: ScreenUtil().setWidth(22),
                    height: ScreenUtil().setHeight(22),
                  ),
                  onTap: () {
                    currentPage =1;

                    search = textEditingController.text;

                    typeid ="";

                    requestMaterial(false);
                    },
                ),
                SizedBox(
                  width: ScreenUtil().setWidth(18),
                )
              ],
            ),
          ),
          SizedBox(
            height: ScreenUtil().setHeight(18),
          ),
          cate(),
          SizedBox(
            height: ScreenUtil().setHeight(18),
          ),
          Expanded(child: buildRefresh())
        ],
      ),
    );
  }

  void refresh() {}
  void load() {
    currentPage++;
    requestMaterial(true);
  }

  TextStyle b() {
    return TextStyle(
        color: Color(0xff101010),
        fontSize: ScreenUtil().setSp(16),
        fontWeight: FontWeight.bold);
  }

  String materialTypeUrl = "";

  Widget sheetDialogItem(int index) {
    return GestureDetector(
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              materialTypeUrl.isEmpty
                  ? Image.asset(
                      "assets/assist/wenjian1.png",
                      width: ScreenUtil().setWidth(55),
                      height: ScreenUtil().setHeight(55),
                    )
                  : Image.network(materialTypeUrl,
                      width: ScreenUtil().setWidth(55),
                      height: ScreenUtil().setHeight(55)),
              SizedBox(
                height: ScreenUtil().setHeight(6),
              ),
              Text(
                "${list[index].name}",
                style: b1(),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
                textAlign: TextAlign.center,
              ),
              SizedBox(
                height: ScreenUtil().setHeight(6),
              ),
              Row(
                children: <Widget>[
//                    Text(
//                      "7.22 15:37",
//                      style: grey(),
//                    ),
                  SizedBox(
                    width: ScreenUtil().setWidth(6),
                  ),
                  Text(
                    "${list[index].goodsStatus == 1 ? "已上架" : ""}",
                    style: TextStyle(
                        color: Color(0xff00C91E),
                        fontSize: ScreenUtil().setSp(12)),
                  )
                ],
              )
            ],
          ),
          Positioned(
            child: GestureDetector(
              child: Image.asset("assets/assist/xuanze.png",
                  width: ScreenUtil().setWidth(21),
                  height: ScreenUtil().setHeight(
                      list[index].check ? 21 : 0)),
              onTap: () {},
            ),
            top: 0,
            right: 0,
          )
        ],
      ),
      onTap: () {
        for (int i = 0; i < list.length; i++) {
          list[i].check = false;
        }

        list[index].check = true;

        taskid = list[index].id.toString();
        name = list[index].name;
//              check = !check;

        setState(() {});
      },
    );
  }

  TextStyle b1() {
    return TextStyle(
        color: Color(0xff101010), fontSize: ScreenUtil().setSp(14));
  }

  TextStyle grey() {
    return TextStyle(
        color: Color(0xffa7a7a7), fontSize: ScreenUtil().setSp(14));
  }

  @override
  dispose(){
    refreshController.dispose();
  }

  String search = "";
  int currentPage=1;
  String typeid = "";
  String taskid = "";
  String name = "";
  void requestMaterialType() async {
//    DialogUtil.showloadingdialog(context);

    try {
      Map<String, dynamic> map = Map<String, dynamic>();

//      map["member_id"] = Constants.memberInfoEntity.data.memberId;
      map["member_id"] = Constants.memberInfoEntity.data.memberId;
      map["type_id"] = "";
      map["keyword"] = search;
      map["page"] = currentPage;

      Map<String, dynamic> map1 = await HttpClient.requestLogin(
          Config.requestApi + 'light/task/type',
          data: map);

//      v.dismiss();
      MaterialTypeEntity loginEntity = new MaterialTypeEntity();

      loginEntity = materialTypeEntityFromJson(loginEntity, map1);

//      DialogUtil.pop(context);
      if (loginEntity.code == null || loginEntity.code != 200) {
//        Fluttertoast.showToast(msg: "null");
        Toast.show(msg: loginEntity.msg);

        return;
      }
      if (loginEntity.code == 200) {
//        Toast.show(msg: "创建成功");
//        NaviUtil.pop(this.context);



        materialTypeEntity = loginEntity;
        setState(() {});
      }
    } catch (e) {
      print(e.toString());
//      DialogUtil.pop(context);
    }
  }

  void requestMaterial(bool load) async {
//    DialogUtil.showloadingdialog(context);
    try {
      Map<String, dynamic> map = Map<String, dynamic>();


      map["type_id"] = typeid;
      map["keyword"] = textEditingController.text.toString();
      map["page"] = currentPage;

      Map<String, dynamic> map1 = await HttpClient.requestLogin(
          Config.requestApi + 'light/task/index',
          data: map);

//      v.dismiss();
      MaterialListEntity loginEntity = new MaterialListEntity();

      loginEntity = materialListEntityFromJson(loginEntity, map1);

//      DialogUtil.pop(context);
      if (loginEntity.code == null || loginEntity.code != 200) {
//        Fluttertoast.showToast(msg: "null");
        Toast.show(msg: loginEntity.msg);
        return;
      }
      if (loginEntity.code == 200) {
//        Toast.show(msg: "创建成功");
//        NaviUtil.pop(this.context);


//        loginEntity.data.data
//            .retainWhere((element) => element.goodsStatus == 0);
//        if(load){
//
//          refreshController.refreshCompleted();
//          refreshController.
//        }

//        materialListEntity = loginEntity;
        setState(() {});

//        if(materialListEntity.data.)
        if(load){

          if(loginEntity.data.data.length>0){
            list.addAll(loginEntity.data.data);
            refreshController.loadComplete();
          }else{
            refreshController.loadNoData();

          }

//        refreshController.loadNoData();
        }else{

          list.clear();
          if(loginEntity.data.data.length>0){
            list.addAll(loginEntity.data.data);
          }

        }
        setState(() {

        });

      }
    } catch (e) {
      print(e.toString());

//DialogUtil.pop(context);
    }finally{

    }
  }
}
